package com.nightsoul.retrofit.test.service;

import java.util.List;
import java.util.Map;

import okhttp3.RequestBody;

import com.nightsoul.retrofit.test.pojo.User;

import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part;
import retrofit2.http.Path;
import retrofit2.http.Query;
import retrofit2.http.QueryMap;

public interface UserService {
	
	@GET("users/list")
	Call<List<User>> listUsers();
	
	@GET("group/{id}/users")
	Call<List<User>> groupList(@Path("id") int groupId);
	
	@GET("group/{id}/users")
	Call<List<User>> groupList(@Path("id") int groupId, @Query("sort") String sort);
	
	@GET("group/{id}/users")
	Call<List<User>> groupList(@Path("id") int groupId, @QueryMap Map<String, String> options);
	
	@POST("users/new")
	Call<User> createUser(@Body User user);
	
	@FormUrlEncoded
	@POST("user/edit")
	Call<User> updateUser(@Field("id") Integer id, @Field("name") String name, @Field("password") String password);
	
	/**
	 * @part必须如此书写才可上传成功：@Part("photo\"; filename=\"image.png\"")
	 * @param photo
	 * @param description
	 * @return
	 */
	@Multipart
	@POST("user/photo")
	Call<User> updateUser(@Part("photo\"; filename=\"image.png\"") RequestBody photo, @Part("description") RequestBody description);
}
